home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-02
/
pas_0593.zip
/
3DEQU.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-05-30
|
3KB
|
92 lines
{─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
Msg : 159 of 286
From : Steve Connet 1:300/15.0 11 May 93 11:16
To : Tony Wouters
Subj : Pascal 3D equations
────────────────────────────────────────────────────────────────────────────────
This message was from SCOTT CAMPBELL to JAMES MASTERS
originally in conference PASCAL langua
and was forwarded to you by STEVE CONNET
----------------------------------------
Okay, here's the equations for 3D rotations...
x,y,z are the coordinates of the point you want to rotate.
rx,ry,rz are the amount of rotation you want (in degrees) for x,y,z}
x1:=round(cos(rad(ry))*x-sin(rad(ry))*z);
z1:=round(sin(rad(ry))*x+cos(rad(ry))*z);
x:=round(cos(rad(rz))*x1+sin(rad(rz))*y);
y1:=round(cos(rad(rz))*y-sin(rad(rz))*x1);
z:=round(cos(rad(rx))*z1-sin(rad(rx))*y1);
y:=round(sin(rad(rx))*z1+cos(rad(rx))*y1);
{
Because in Turbo Pascal, COS and SIN require radians for the argument,
I wrote a short function called RAD() that converts degrees into radians
(I find degrees much easier to visualize) }
function rad(i:integer):real;
begin
rad:=i*(pi/360);
end;
{
Of course, since most computers don't have 3D projection screens <G>,
use these equations to provide a sense of perspective to the object,
but with 2D coordinates you can plot on a screen.
x,y,z are from the equations above, and xc,yc,zc are the center points
for the object that you are rotating... I recommend setting xc,yc at 0,0
but zc should be very high (+100). }
x2:=trunc((xc*z-x*zc)/(z-zc));
y2:=trunc((yc*z-y*zc)/(z-zc));
{
Alternatively, if you don't want to bother with perspective, just drop
the z values, and just plot the (x,y) instead.
To use these equations, pick a 3D object and figure out what the 3D
coordinates are for each point on the object. You will have to have some
way to let the computer know which two points are connected. For the
cube that I did, I had one array for the points and one for each face
of the cube. That way the computer can draw connecting lines for each
face with a simple for-loop. }
type
FACELOC=array[1..4] of integer
POINTLOC=record;
x,y,z:integer;
end;
const
face_c:array [1..6] of faceloc =(
(1,2,3,4),
(5,6,2,1),
(6,5,8,7),
(4,3,7,8),
(2,6,7,3),
(5,1,4,8));
point_c:array [1..8] of pointloc =(
(-25, 25, 25),
( 25, 25, 25),
( 25,-25, 25),
(-25,-25, 25),
(-25, 25,-25),
( 25, 25,-25),
( 25,-25,-25),
(-25,-25,-25));
{
There you go. I'm not going to get much more complicated for now. If you
can actually get these equations/numbers to work (and I haven't forgotten
anything!) leave me another message, and I'll give you some advice for
filling in the sides of the object (so that you can only see 3 sides at
once) and some advice to speed things up abit. If you have any problems
with whats here, show some other people, and maybe as a collective you can
figure it out. Thats how I got this one started!
Send me a message sometime and let me know if I did forget something....}